package config

import (
	"fmt"
	"gopkg.in/ini.v1"
	"os"
)

var (
	cfg *ini.File
	err error
)

func Init() {
	//https://ini.unknwon.cn/docs/advanced/map_and_reflect

	cfg, err = ini.Load("my.ini")
	if err != nil {
		fmt.Printf("Fail to read file: %v", err)
		os.Exit(1)
	}

	var str = getConfig("mysql", "database")
	fmt.Println("mysql-database:", str)
}

func getConfig(key1 string, key2 string) string {
	if key2 == "" {
		return ""
	}

	return cfg.Section(key1).Key(key2).String()
}
